home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / wattcp / src / pcintr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  1.4 KB  |  75 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4. #include <wattcp.h>
  5.  
  6. /*
  7.  * pcintr - add interrupt based processing, improve performance
  8.  *          during disk slowdowns
  9.  *
  10.  * wintr_init()     - call once
  11.  * wintr_shutdown() - called automatically
  12.  * wintr_enable()   - enable interrupt based calls
  13.  * wintr_disable()  - diable interrupt based calls (default)
  14.  * (*wintr_chain)() - a place to chain in your own calls, must live
  15.  *                    within something like 1K stack
  16.  *
  17.  */
  18.  
  19.  
  20. #define TIMER 0x08
  21. void (*wintr_chain)() = NULL;
  22.  
  23. static byte locstack[ 2048 ];
  24. static word on = 0;
  25. static word inside = 0;
  26. static word oldss, oldsp;
  27. static void interrupt (*oldint)();
  28.  
  29. static void interrupt newint(void)
  30. {
  31.     (*oldint)();
  32.     if ( !sem_up( &inside )) {
  33.     if ( on ) {
  34.         disable();
  35.         oldss = _SS;
  36.         oldsp = _SP;
  37.         _SS = _DS;
  38.         _SP = FP_OFF( &locstack[ sizeof( locstack ) - 4 ]);
  39.         enable();
  40.  
  41.         if ( wintr_chain )
  42.         (*wintr_chain)();
  43.         tcp_tick( NULL );
  44.  
  45.         disable();
  46.         _SS = oldss;
  47.         _SP = oldsp;
  48.             enable();
  49.         }
  50.         inside = 0;
  51.     }
  52. }
  53.  
  54. void wintr_enable(void)
  55. {
  56.     on = 1;
  57. }
  58.  
  59. void wintr_disable(void)
  60. {
  61.     on = 0;
  62. }
  63.  
  64. void wintr_shutdown(void)
  65. {
  66.     setvect( TIMER, oldint );
  67. }
  68. void wintr_init(void)
  69. {
  70.     atexit( wintr_shutdown );
  71.     oldint = getvect( TIMER );
  72.     setvect( TIMER, newint );
  73. }
  74.  
  75.